/**
 * 种子孵化器
 */
export default class Seed {
  constructor(imgSrc = '', width = 0, height = 0, x = 0, y = 0) {
    this.img = new Image()
    this.img.src = imgSrc

    this.width = width
    this.height = height

    this.x = x
    this.y = y
    this.index = 0
    this.VDindex = 0
    this.voiceData = []
    this.visible = true
    this.valum = 150
  }

  /**
   * 将种子孵化出来
   */
  drawToCanvas(ctx, loaded, voiceData) {
    if (!this.visible)
      return

    if (this.VDindex < voiceData.length - 2) {
      this.VDindex++
    } else {
      this.VDindex = 0
    }
    let colorIndex = ((voiceData[this.VDindex][27] / 250) * 35).toFixed(0)
    ctx.fillStyle = 'rgba(255,255,255,1)';
    ctx.globalCompositeOperation = 'lighter';

    for (let i = 0; i < 40; i++) {
      ctx.fillStyle = 'rgba(' + this.colors[i] + ',1)';
      ctx.fillRect(0, ((canvas.height / 40) - 1) * i + (i * 1), voiceData[this.VDindex][i], (canvas.height / 40) - 1)
    }
    ctx.restore();
  }
}